using System.Diagnostics;
using mshtml;
using OFX.Aggregator.WebScraping.Infrastructure;

namespace OFX.Aggregator.WebScraping.Implementation
{
	internal class HtmlElementWrapper : IHtmlElement
	{
		private readonly HtmlDocumentManager documentManager;
		private readonly IHTMLElement element;

		[DebuggerStepThrough]
		public HtmlElementWrapper(IHTMLElement element, HtmlDocumentManager documentManager)
		{
			this.element = element;
			this.documentManager = documentManager;
		}

		#region Implementation of IHtmlElement

		public IHtmlDocument Document
		{
			[DebuggerStepThrough]
			get { return this.documentManager.GetWrapper((IHTMLDocument) this.element.document); }
		}

		public string TagName
		{
			[DebuggerStepThrough]
			get { return this.element.tagName; }
		}

		public string InnerText
		{
			[DebuggerStepThrough]
			get { return this.element.innerText; }
			[DebuggerStepThrough]
			set { this.element.innerText = value; }
		}

		public string InnerHtml
		{
			[DebuggerStepThrough]
			get { return this.element.innerHTML; }
			[DebuggerStepThrough]
			set { this.element.innerHTML = value; }
		}

		public string OuterHtml
		{
			[DebuggerStepThrough]
			get { return this.element.outerHTML; }
			[DebuggerStepThrough]
			set { this.element.outerHTML = value; }
		}

		public IHtmlElementCollection Children
		{
			[DebuggerStepThrough]
			get { return this.documentManager.GetWrapper((IHTMLElementCollection) this.element.children); }
		}

		[DebuggerStepThrough]
		public void Focus()
		{
			((IHTMLElement2) this.element).focus();
		}

		[DebuggerStepThrough]
		public void Click()
		{
			this.element.click();
		}

		[DebuggerStepThrough]
		public string GetAttribute(string name)
		{
			return (string) this.element.getAttribute(name, 0);
		}

		#endregion
	}
}